#include "qplpsupplier.h"

QPLPSupplier::QPLPSupplier(QStringList supplier, QWidget *parent )
: QWidget(parent),m_first(true)
{
	ui.setupUi(this);
	connect(ui.add,SIGNAL(clicked()),this,SLOT(buttonClicked()));
	ui.suppliervalue->setText("");
	ui.refvalue->setText("");
	if(supplier.isEmpty())
	{
		QCompleter* completer = new QCompleter(supplier);
		ui.suppliervalue->setCompleter(completer);
	}
}

QPLPSupplier::~QPLPSupplier()
{
	if(ui.suppliervalue->completer())
		delete ui.suppliervalue->completer();
}

void QPLPSupplier::set(QStringList supplier)
{
	if(supplier.isEmpty())
	{
		if(ui.suppliervalue->completer())
			delete ui.suppliervalue->completer();
		QCompleter* completer = new QCompleter(supplier);
		ui.suppliervalue->setCompleter(completer);
	}
}

void QPLPSupplier::setFirst(bool firstOne)
{
	QString style = QString::fromUtf8("QPushButton{				border: 0px solid white;"
																"background-color: white;"
																"image: url(./Ressources/%1); image-position: right;}"
												"QPushButton:hover {	border: 0px solid white;"
																	"background-color: qlineargradient(x1: 0.1, y1: 0, x2: 1, y2: 0,"
																	"stop: 0 #FFFFFF, stop: 1  #FFE69E); }");
	if(firstOne)
		ui.add->setStyleSheet(style.arg("deploy.png"));
	else
		ui.add->setStyleSheet(style.arg("Important.png"));
	m_first = firstOne;
}

void QPLPSupplier::buttonClicked()
{
	if(m_first)
		emit added();
	else
		emit deleted();
}